package com.gin.no_gay_alliance.adpter.pm;

import android.content.Context;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;

import com.gin.common.utils.TimeUtils;
import com.gin.jackson.utils.ObjectUtils;
import com.gin.no_gay_alliance.adpter.base.BaseBindingRecyclerViewAdapter;
import com.gin.no_gay_alliance.customview.ContentWebViewRender;
import com.gin.no_gay_alliance.databinding.ItemPriMsgReplyBinding;
import com.gin.no_gay_alliance.utils.ViewUtils;
import com.gin.no_gay_alliance.viewmodel.PriMsgReplyItem;

import java.util.ArrayList;
import java.util.List;

/**
 * 私信回复适配器
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/1 15:45
 **/
public class PriMsgReplyAdapter extends BaseBindingRecyclerViewAdapter<ItemPriMsgReplyBinding, PriMsgReplyItem> {
    private final ContentWebViewRender contentWebViewRender;

    public PriMsgReplyAdapter(Context context) {
        this(context, new ArrayList<>());
    }

    public PriMsgReplyAdapter(@NonNull Context context, @NonNull List<PriMsgReplyItem> data) {
        super(context, data);
        contentWebViewRender = new ContentWebViewRender(context, handler);
    }

    /**
     * 绑定数据
     *
     * @param holder
     * @param b        绑定对象
     * @param position 位置
     * @param item
     */
    @Override
    protected void onBindViewHolder(ViewHolder<ItemPriMsgReplyBinding> holder, @NonNull ItemPriMsgReplyBinding b, int position, PriMsgReplyItem item) {
        b.ulv.init(item.userId, item.username, item.avatar, 48, 0);
        b.tvTitle.setText(item.title);
        ViewUtils.setGone(ObjectUtils.isEmpty(item.title), b.tvTitle);
        b.tvPostTime.setText(TimeUtils.format(item.timestamp));
        // 正文渲染
        contentWebViewRender.render(position, b.layoutContent, holder, item.nodes);

    }

    /**
     * 构造binding对象
     *
     * @param inflater
     * @return T
     */
    @NonNull
    @Override
    protected ItemPriMsgReplyBinding buildBinding(LayoutInflater inflater) {
        return ItemPriMsgReplyBinding.inflate(inflater);
    }
}
